package com.mca.framework.stream;

import com.mca.framework.lambda.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class DemoFilter1 {
    public static void main(String[] args) {
        //获取所有年龄20岁以下的学生
        List<Student> studentList = new ArrayList<>();
        studentList.add(new Student(1,"张三","M",19,true));
        studentList.add(new Student(1,"李四","M",18,false));
        studentList.add(new Student(1,"王五","F",21,true));
        studentList.add(new Student(1,"赵六","F",20,false));
        //java8 Stream 中间操作
        Stream<Student> studentStream = studentList.stream().filter(s -> s.getAge() < 20);
        //终端操作
        List<Student> studentsList = studentStream.collect(Collectors.toList());
//        List<Student> list = studentsList.stream().filter(s -> s.getAge() < 20).collect(Collectors.toList());
//        System.out.println(list);
        //stream   filter(Student::getIsPass) 返回过滤为true的数据
        List<Student> result = studentsList.parallelStream().filter(Student::getIsPass).collect(Collectors.toList());
        System.out.println(result);
    }
}
